//
//  YingDanTableViewCell.m
//  C17
//
//  Created by dllo on 16/3/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "YingDanTableViewCell.h"
#import "movieThirdCollectionViewCell.h"
@interface YingDanTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property(nonatomic,retain)NSMutableArray *movieArr;
@end

@implementation YingDanTableViewCell

- (void)awakeFromNib {
    // Initialization code
    
    [self.movieThirdcollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([movieThirdCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:@"movieThirdcollectionView"];
}

-(void)setPage:(NSInteger)page{
    self.movieArr=[NSMutableArray array];
        AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
        NSDictionary *parameters = @{@"id":self.pagelist_id,@"page":@"1"};
        [manager POST:@"http://ting.weibo.com/movieapp/Pagelist/recommendmovie" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            for (NSDictionary *dic in responseObject[@"data"][@"list"]) {
                [self.movieArr addObject:dic];
            }
            
            if (page==2) {
                AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
                NSDictionary *parameters = @{@"id":self.pagelist_id,@"page":@"2"};
                [manager POST:@"http://ting.weibo.com/movieapp/Pagelist/recommendmovie" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    for (NSDictionary *dic in responseObject[@"data"][@"list"]) {
                        [self.movieArr addObject:dic];
                    }
                    [self.movieThirdcollectionView reloadData];
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                }];
            }
            else if (page==3){
                AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
                NSDictionary *parameters = @{@"id":self.pagelist_id,@"page":@"2"};
                [manager POST:@"http://ting.weibo.com/movieapp/Pagelist/recommendmovie" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    for (NSDictionary *dic in responseObject[@"data"][@"list"]) {
                        [self.movieArr addObject:dic];
                    }
                    AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
                    NSDictionary *parameters = @{@"id":self.pagelist_id,@"page":@"3"};
                    [manager POST:@"http://ting.weibo.com/movieapp/Pagelist/recommendmovie" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                        for (NSDictionary *dic in responseObject[@"data"][@"list"]) {
                            [self.movieArr addObject:dic];
                        }
                        [self.movieThirdcollectionView reloadData];
                    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    }];
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                }];
            }
            else{
                [self.movieThirdcollectionView reloadData];
            }
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        }];
}
#pragma mark CollectionView的协议方法
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.movieArr.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    movieThirdCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"movieThirdcollectionView" forIndexPath:indexPath];
    NSDictionary *dic=self.movieArr[indexPath.row];
    [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:dic[@"poster_url"]]];
    cell.movieName.text=dic[@"name"];
    return cell;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
